/*
 * stdlib.h
 * This file has no copyright assigned and is placed in the Public Domain.
 * This file is a part of the clang port package.
 * No warranty is given; refer to the file DISCLAIMER within the package.
 *
 * Definitions for common types, variables, and functions.
 *
 */

#ifndef _CLANG_PORT_STDLIB_H_
#define _CLANG_PORT_STDLIB_H_

/* All the headers include this file. */
#ifndef __IMPL_CLANG_PORT_API_
#	include <_clang_port.h>
#else
#	include <include/_clang_port.h>
#endif

#include <stddef.h>

#ifndef __IMPL_CLANG_PORT_API_
/*
 * RAND_MAX is the maximum value that may be returned by rand.
 * The minimum is zero.
 */
#define	RAND_MAX	0x7FFF

/*
 * These values may be used as exit status codes.
 */
#define	EXIT_SUCCESS	0
#define	EXIT_FAILURE	1

#ifndef MAX_PATH
#define	MAX_PATH	(260)
#endif

#define	_MAX_PATH	MAX_PATH
#define	_MAX_DRIVE	(3)
#define	_MAX_DIR	256
#define	_MAX_FNAME	256
#define	_MAX_EXT	256


#endif // __IMPL_CLANG_PORT_API_


#ifdef __cplusplus
extern "C" {
#endif


#ifndef __IMPL_CLANG_PORT_API_
double atof	(const char*);
int atoi	(const char*);
long atol	(const char*);

long strtol	(const char*, char**, int);
unsigned long strtoul	(const char*, char**, int);


size_t wcstombs	(char*, const wchar_t*, size_t);
int wctomb		(char*, wchar_t);

int mblen		(const char*, size_t);
size_t mbstowcs	(wchar_t*, const char*, size_t);
int mbtowc		(wchar_t*, const char*, size_t);

int rand	(void);
void srand	(unsigned int);

void* calloc	(size_t, size_t);
void* malloc	(size_t);
void* realloc	(void*, size_t);
void free	(void*);
void abort	(void) ;
void exit	(int) ;

int atexit	(void (*)(void));

int system	(const char*);
char* getenv	(const char*);

/* bsearch and qsort are also in non-ANSI header search.h  */
void* bsearch (const void*, const void*, size_t, size_t, 
			       int (*)(const void*, const void*));
void qsort(void*, size_t, size_t,
			   int (*)(const void*, const void*));

int abs	(int) ;
long labs (long) ;

/*
 * div_t and ldiv_t are structures used to return the results of div and
 * ldiv.
 */
typedef struct { int quot, rem; } div_t;
typedef struct { long quot, rem; } ldiv_t;

div_t div (int, int) ;
ldiv_t ldiv (long, long) ;

#endif // __IMPL_CLANG_PORT_API_

#ifdef __cplusplus
}
#endif

#endif	/* Not _CLANG_PORT_STDLIB_H_ */

